package com.polylink.sys.service.impl;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Value;

/**
 *@author xiliang.xiao
 *@date 2015年4月3日 下午4:43:31
 *
 **/
public class UserPasswordEncrypt {

	@Value("${psw.encypt.algorithmName}")
	private static String algorithmName = "md5";
	@Value("${psw.encypt.hashIterations}")
	private static int hashIterations = 2;
	
	public static String getAlgorithmName() {
		return algorithmName;
	}

	public static void setAlgorithmName(String algorithmName) {
		UserPasswordEncrypt.algorithmName = algorithmName;
	}

	public static int getHashIterations() {
		return hashIterations;
	}

	public static void setHashIterations(int hashIterations) {
		UserPasswordEncrypt.hashIterations = hashIterations;
	}

	/**
	 * 加密
	 * @param psw
	 * @return
	 */
	public static String encrypt(String psw){
		return new SimpleHash(algorithmName, psw, null, hashIterations).toHex();
	}
}
